# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=xh
pkgver=0.22.0
pkgrel=0
pkgdesc="Yet another HTTPie clone"
url="https://github.com/ducaale/xh"
# riscv64: blocked by rust/cargo
# s390x: fails to build terminal_size crate
arch="all !riscv64 !s390x"
license="MIT"
makedepends="
	cargo
	cargo-auditable
	oniguruma-dev
	openssl-dev
	"
subpackages="
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	"
source="https://github.com/ducaale/xh/archive/v$pkgver/xh-$pkgver.tar.gz
	Cargo-update.patch"
options="net" # fetch dependencies

# Link with system-provided oniguruma library (instead building from source
# and bundling).
export RUSTONIG_DYNAMIC_LIBONIG=1

_cargo_opts="--frozen --no-default-features --features native-tls"


prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build $_cargo_opts --release
}

check() {
	cargo test $_cargo_opts
}

package() {
	install -D -m755 target/release/$pkgname -t "$pkgdir"/usr/bin/

	ln -s xh "$pkgdir"/usr/bin/xhs

	install -Dm 644 doc/xh.1 "$pkgdir"/usr/share/man/man1/xh.1

	install -Dm 644 completions/xh.bash "$pkgdir"/usr/share/bash-completion/completions/xh
	install -Dm 644 completions/xh.fish "$pkgdir"/usr/share/fish/vendor_completions.d/xh.fish
	install -Dm 644 completions/_xh "$pkgdir"/usr/share/zsh/site-functions/_xh
}

sha512sums="
8f7ba8ab5db5d498d022d92e7cad629838649a460dcfd180579a021d3825cd063b3274ef2dee818f07cb3412546f887c12463332ec55e12a0a1f0e4e211ec054  xh-0.22.0.tar.gz
7236c7d8400740a45291954d92c99b195e85365058f8c2db3b2c088d9f23755f00a32a60808da82aa682e957a9e100c67985e7ed9e9cebab58eb78644bfad728  Cargo-update.patch
"
